import { 
  UPDATE_LINKNAME, 
  UPDATE_LINKMOBILE, 
  UPDATE_BUILDING, 
  UPDATE_BUILDERID, 
  UPDATE_FLOORNO, 
  UPDATE_DETAIL,
  UPDATE_IS_NEW_ADDRESS,
  UPDATE_ADDRESS,
  UPDATE_ALL_TO_EMPTY,
  UPDATE_ADDRESS_CLICK
} from './../mutation_types'

const state = {
  isNewAddress: false,
  linkname: '',
  linkmobile: '',
  building: '未选',
  builderId: '',
  floorNo: ['1楼'],
  detail: '',
  address: '',
  addressClick: false
}

const mutations = {
  [UPDATE_LINKNAME](state, linkname) {
    state.linkname = linkname
  },
  [UPDATE_LINKMOBILE](state, linkmobile) {
    state.linkmobile = linkmobile
  },
  [UPDATE_BUILDING](state, building) {
    state.building = building
  },
  [UPDATE_BUILDERID](state, builderId) {
    state.builderId = builderId
  },
  [UPDATE_FLOORNO](state, floorNo) {
    state.floorNo = floorNo
  },
  [UPDATE_DETAIL](state, detail) {
    state.detail = detail
  },
  [UPDATE_IS_NEW_ADDRESS](state, isNewAddress) {
    state.isNewAddress = isNewAddress
  },
  [UPDATE_ADDRESS_CLICK](state, addressClick) {
    state.addressClick = addressClick
  },
  [UPDATE_ADDRESS](state, address) {
    state.address = address
    state.linkname = address.consignee
    state.linkmobile = address.phone
    state.building = address.builderName
    state.builderId = address.builderId
    state.floorNo[0] = address.floorNo
    state.detail = address.address
  },
  [UPDATE_ALL_TO_EMPTY](state, content) {
    state.isNewAddress = false
    state.address = ''
    state.linkname = ''
    state.linkmobile = ''
    state.building = ''
    state.builderId = ''
    state.floorNo = ['1楼 ']
    state.detail = ''
  }
}

export default {
  state,
  mutations
}